package com.ruoyi.media.forestApi;

import com.dtflys.forest.annotation.*;
import com.dtflys.forest.callback.OnLoadCookie;
import com.dtflys.forest.callback.OnSaveCookie;
import com.dtflys.forest.http.ForestResponse;

import java.io.File;
import java.util.Map;

/**
 * 微信所有的远程调用接口
 */
@BaseRequest(
    baseURL = "https://mp.weixin.qq.com", // 默认域名
    headers = {
        "Accept-Encoding: gzip",
        "referer:https://mp.weixin.qq.com/",// 默认请求头
        "userAgent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36",
        "xRequestedWith:XMLHttpRequest"
    }
)
public interface WechatMpApi {

    /**
     * 根据链接获取数据
     * @param url
     * @return
     */
    @Get("{contentUrl}")
    String queryArticleContent(@Var("contentUrl")String url);

    /**
     * 获取指定cookies的token值
     * @param cookie
     * @return
     */
    @Request(url = "/")
    ForestResponse queryToken(@Header("cookie") String cookie);

    /**
     * 跳转登录首页
     * @param token
     * @return
     */
    @Get(url = "/cgi-bin/home?t=home/index&lang=zh_CN&token=${token}")
    String toIndex(@Var("token") String token,OnLoadCookie onLoadCookie);


    /**
     * 跳转微信小程序的首页获取参数
     * @param token
     * @return
     */
    @Get(url = "/wxamp/home/guide?lang=zh_CN&token=${token}")
    String toMiniProgramIndex(@Var("token") String token,OnLoadCookie onLoadCookie);

    /**
     * 根据关键词查询公众号
     * @return
     */
    @Request(url = "/cgi-bin/searchbiz?action=search_biz&begin=0&count=5&query={0}&token={1}&lang=zh_CN&f=json&ajax=1")
    ForestResponse searchMpByKeyWord(String keyword, String token,OnLoadCookie onLoadCookie);

    /**
     * 根据biz参数获取公众号文章链接
     * @param biz
     * @param token
     * @param onLoadCookie
     * @return
     */
    @Request(url= "cgi-bin/appmsg?action=list_ex&begin=0&count=5&fakeid={0}&type=9&query=&token={1}&lang=zh_CN&f=json&ajax=1")
    String searchMpArticleByBiz(String biz,String token,OnLoadCookie onLoadCookie);

    /**
     * 获取账号设置页数据
     * @param token
     * @return
     */
    @Request(url = "/cgi-bin/settingpage?t=setting/index&action=index&token={0}&lang=zh_CN&f=json")
    ForestResponse queryDataInfo(String token,OnLoadCookie onLoadCookie);

    /**
     * 获取公众号收款公司主体名称
     * @return
     */
    @Request(url = "promotion/publisher/publisher_mgr?req_type=1&token={0}&appid=&spid=&_={1}")
    ForestResponse queryBankInfoData(String token,String dataTime,OnLoadCookie onLoadCookie);

    /**
     * 获取公众号收益数据
     * @return
     */
    @Request(url = "promotion/publisher/publisher_stat?action=overview")
    ForestResponse queryIncomeData(@Query Map<String, Object> params, OnLoadCookie onLoadCookie);

    /**
     * 获取阅读量数据
     * @return
     */
    @Post(url = "misc/datacubequery")
    ForestResponse queryReadNumData(@Body Map<String, Object> formData, OnLoadCookie onLoadCookie);

    /**
     * 根据图片链接裁剪图片
     * @param formData
     * @param onLoadCookie
     * @return
     */
    @Post(url = "cgi-bin/cropimage?action=crop_multi")
    ForestResponse cropImages(@Body Map<String, Object> formData,OnLoadCookie onLoadCookie);






    /**
     * 保存素材 & 草稿
     * @return
     */
    @Post(url = "cgi-bin/operate_appmsg?t=ajax-response&sub=create&type=${type}&token=${token}&lang=zh_CN",
        headers = {
            "content-type: application/x-www-form-urlencoded; charset=UTF-8",
        })
    String saveDraught(@Body Map<String, Object> body,@Var("token")String token,@Var("type")int type, OnLoadCookie onLoadCookie);



//    ====================================================文章检查分割线================================================


    /**
     * 发布时检查音乐
     * @return
     */
    @Post(url = "cgi-bin/masssend?action=check_music",headers = {
        "referer:https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit&action=edit&type=77" +
            "&appmsgid=${appMsgId}&token=${token}&lang=zh_CN",
    })
    String checkMusic(@Body Map<String, Object> body,@Query("appMsgId")String appMsgId,@Query("token")String token, OnLoadCookie onLoadCookie);


    /**
     * 发布时检查广告
     * @param body
     * @param token
     * @param onLoadCookie
     * @return
     */
    @Post(url = "cgi-bin/masssend?action=check_ad&token=${token}&lang=zh_CN",
        headers = {
            "referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit&" +
                "action=edit&type=77&appmsgid=${appMsgId}&token=${token}&lang=zh_CN"
        })
    String checkAd(@Body Map<String, Object> body,@Query("appMsgId")String appMsgId,@Query("token")String token, OnLoadCookie onLoadCookie);


    /**
     * 发布时检查账号密码
     * @return
     */
    @Post(url = "cgi-bin/masssend?action=check_same_material",
        headers = {
            "referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit&action=edit" +
                "&type=77&appmsgid=${appMsgId}&token=${token}&lang=zh_CN"
        })
    String checkSameMaterial(@Body Map<String, Object> body,@Query("appMsgId")String appMsgId,@Query("token")String token, OnLoadCookie onLoadCookie);


    /**
     * 检查文章原创度
     * @param body
     * @param token
     * @param onLoadCookie
     * @return
     */
    @Post(url = "cgi-bin/masssend?action=get_appmsg_copyright_stat&token=${token}&lang=zh_CN",headers = {
        "referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit&" +
            "action=edit&type=77&appmsgid=${appMsgId}&token=${token}&lang=zh_CN"
    })
    String getAppMsgCopyright(@Body Map<String, Object> body,@Query("appMsgId")String appMsgId,@Query("token")String token, OnLoadCookie onLoadCookie);



//    ==================================================分割线=========================================================


    /**
     * 获取广告列表
     * @return
     */
    @Get(url = "merchant/ad_seller_manager?action=get_ad_setting&token=${token}&lang=zh_CN&f=json&ajax=1&random=${random}",headers = {
        "referer:https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit&action=edit&type=77&token=${token}&lang=zh_CN"
    })
    String getAdSetting(@Var("token") String token,@Var("random")double random,OnLoadCookie onLoadCookie);


    /**
     * 发布前对参数的封装
     * @return
     */
    @Get(url = "cgi-bin/masssendpage?f=json&token=${token}&lang=zh_CN&f=json&ajax=1&random=${random}",headers = {
        "referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit&action=edit" +
            "&type=177appmsgid=${appMsgId}&token=${token}&lang=zh_CN"
    })
    String massSendArticle(@Body Map<String, Object> body,@Var("appMsgId") String appMsgId,@Var("token") String token,@Var("random")double random, OnLoadCookie onLoadCookie);



    /**
     * 发送文章
     * @param body
     * @return
     */
    @Post(url = "cgi-bin/masssend?action=time_send&t=ajax-response&token=${token}&lang=zh_CN",headers = {
        "referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit" +
            "&action=edit&type=177appmsgid=${appmsgid}&token=${token}&lang=zh_CN"
    })
    String sendArticles(@Body Map<String, Object> body,@Var("token")String token,@Var("appmsgid")String appmsgid,OnLoadCookie onLoadCookie);


    /**
     * 获取极致了数据最新收录公众号
     * @return
     */
    @Get(url = "https://www.jzl.com/fbmain/account/v1/last_mpaccount")
    String queryNewMpJzlData();


    /**
     * 开通流量主（请求加id）
     * @param token
     * @param Body
     * @param onLoadCookie
     * @return
     */
    @Post(url = "promotion/publisher/publisher_mgr",headers = {
        "referer: https://mp.weixin.qq.com/cgi-bin/frame?t=ad_system/common_simple_frame&t1=publisher/publisher_open&token=${token}"
    })
    String publisherMgr(@Var("token")String token,@Body Map<String,Object> Body,OnLoadCookie onLoadCookie);




    /**
     * 开通流量主（获取uuid）
     * @param token
     * @param time
     * @param onLoadCookie
     * @return
     */
    @Get(url = "promotion/publisher/adhelperbind?action=create_uuid&token=${token}&appid=&spid=&_=${time}",headers = {
        "referer: https://mp.weixin.qq.com/cgi-bin/frame?t=ad_system/common_simple_frame&t1=publisher/publisher_open&token=${token}"
    })
    String createUuid(@Var("token")String token,@Var("time")String time,OnLoadCookie onLoadCookie);


    /**
     * 开通流量主 绑定uuid
     * @param uuid
     * @param time
     * @param onLoadCookie
     * @return
     */
    @Get(url = "promotion/publisher/adhelperbind?uuid=${uuid}&action=query_uuid&token=${token}&appid=&spid=&_=${time}",headers = {
        "referer: https://mp.weixin.qq.com/cgi-bin/frame?t=ad_system/common_simple_frame&t1=publisher/publisher_open&token=${token}"
    })
    String queryUuid(@Var("uuid")String uuid,@Var("time")String time,@Var("token")String token, OnLoadCookie onLoadCookie);


    /**
     * 初始化视频数据
     * @param body
     * @param token
     * @param onLoadCookie
     * @return
     */
    @Post(url = "cgi-bin/videoupload?action=init_upload",headers = {
        "content-type: application/x-www-form-urlencoded; charset=UTF-8",
        "referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/videomsg_edit&action=video_edit&type=15&token=${token}&lang=zh_CN"
    })
    String initUpload(@Body Map<String,Object> body,@Var("token")String token,OnLoadCookie onLoadCookie);


    /**
     * 视频文件上传
     * @param token
     * @param onLoadCookie
     * @return
     */
    @Post(url = "cgi-bin/videoupload?action=upload_block&part_sha=dddd&vid=${vid}" +
        "&part_num=${partNum}&f=json&ajax=1&token=${token}&lang=zh_CN&t=${random}",headers = {
        "content-type: application/octet-stream",
        "Cache-Control:no-cache",
        "content-length: ${fileSize}",
        "Host: mp.weixin.qq.com",
        "referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/videomsg_edit&action=video_edit&type=15&token=${token}&lang=zh_CN",
    })
    String uploadVideo(@Var("fileSize")Long fileSize, @Var("vid")String vid, @Var("token")String token,
                       @Var("partNum")int partNum, @Var("random")double random,
                       @Body byte[] bytes,
                       OnLoadCookie onLoadCookie);


    /**
     * 视频完成上传
     * @param vid
     * @param token
     * @param random
     * @return
     */
    @Post(url = "cgi-bin/videoupload?action=upload_finish&vid=${vid}" +
        "&screen_shot_type=1&f=json&ajax=1&token=${token}&lang=zh_CN&t=${random}",headers = {
        "content-type: application/json; charset=UTF-8",
        "referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/videomsg_edit&action=video_edit&type=15&isNew=1&token=${token}&lang=zh_CN"
    })
    String uploadFinish(@Var("vid")String vid,@Var("token")String token,@Var("random")double random,OnLoadCookie onLoadCookie);


    /**
     * 获取ticket
     * @return
     */
    @Get(url = "cgi-bin/appmsg?t=media/videomsg_edit&action=video_edit&type=15&isNew=1&token=${token}&lang=zh_CN")
    String getTicket(@Var("token")String token,OnLoadCookie onLoadCookie);


    /**
     * 获取视频待发文的数据
     * @param count
     * @param token
     * @return
     */
    @Get(url = "cgi-bin/appmsg?action=list&count=${count}&type=15&begin=0&f=json&token=${token}&lang=zh_CN&f=json&ajax=1")
    String getSendVideoIds(@Var("count") int count,@Var("token") String token,OnLoadCookie onLoadCookie);


    /**
     * 公众号获取视频封面链接
     * @param ticket
     * @param token
     * @param time
     * @param onLoadCookie
     * @return
     */
    @Post(url = "cgi-bin/filetransfer?action=upload_cdn&f=json&ticket_id=${originId}" +
        "&ticket=${ticket}&svr_time=${time}",headers = {
        "content-length:${fileSize}",
        "content-type:multipart/form-data",
        "referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/videomsg_edit&action=video_edit&type=15&isNew=1&token=${token}&lang=zh_CN"
    })
    String uploadCdn(@DataFile("file") File file, @Var("originId")String originId,
                     @Var("fileSize")Long fileSize, @Var("ticket")String ticket,
                     @Var("token")String token, @Var("time")Long time,
                     OnLoadCookie onLoadCookie);


    /**
     * 获取公众号绑定视频号的token
     * @return
     */
    @Get(url = "cgi-bin/bindfinder?action=get_bind_token&f=json&ajax=1&token=${token}&lang=zh_CN",headers = {
        "referer: https://mp.weixin.qq.com/cgi-bin/settingpage?t=setting/index&action=index&lang=zh_CN&token=${token}"
    })
    String getBindToken(@Var("token")String token,OnLoadCookie onLoadCookie);


    /**
     * 跟据绑定的token参数获取二维码
     * @param token
     * @param bindToken
     * @return
     */
    @Get(url = "cgi-bin/bindfinder?action=get_bind_qrcode&token=${token}&bind_token=${bindToken}")
    ForestResponse getBindQrcode(@Var("token")String token,@Var("bindToken")String bindToken,OnLoadCookie onLoadCookie);


    /**
     * 公众号账号快速注册(登录)
     * @return
     */
    @Post(url = "cgi-bin/bizlogin?action=startlogin",headers = {
        "content-type: application/x-www-form-urlencoded; charset=UTF-8",
        "referer: https://mp.weixin.qq.com/"
    })
    ForestResponse mpAccountLogin(@Body Map<String, Object> body, OnSaveCookie onSaveCookie);


    /**
     * 获取当前登录页的token
     * @return
     */
    @Get(url = "acct/contractorpage?action=showsubmit&step=3&lang=zh_CN&token=",headers = {
        "referer: https://mp.weixin.qq.com/"
    })
    String getCreateMpToken(OnLoadCookie onLoadCookie);


    /**
     * 公众号账号快速注册(选择国家和地区)
     * @return
     */
    @Post(url = "acct/registerpage?action=savecountry",headers = {
        "content-type: application/x-www-form-urlencoded; charset=UTF-8"
    })
    String savecountry(@Body Map<String, Object> body,OnLoadCookie onLoadCookie);


    /**
     * 保存订阅号服务号类型
     * @return
     */
    @Post(url = "acct/registerpage",headers = {
        "referer: https://mp.weixin.qq.com/acct/contractorpage?action=showreg&step=3&lang=zh_CN",
        "content-type: application/x-www-form-urlencoded; charset=UTF-8"
    })
    String registerpage(@Body Map<String, Object> body,OnLoadCookie onLoadCookie);



    @Post(url = "acct/contractorsubmit",headers = {
        "content-type: application/x-www-form-urlencoded; charset=UTF-8",
        "referer: https://mp.weixin.qq.com/acct/contractorpage?action=showreg&step=3&lang=zh_CN"
    })
    String contractorsubmit(@Body Map<String, Object> body,OnLoadCookie onLoadCookie);


    /**
     * 获取法人验证码的getticket
     * @return
     */
    @Post(url = "cgi-bin/mastersafeqrcode?action=getticket",headers = {
        "content-type: application/x-www-form-urlencoded; charset=UTF-8",
        "referer: https://mp.weixin.qq.com/acct/contractorpage?action=showreg&step=3&lang=zh_CN"
    })
    String mastersafeqrcode(@Body Map<String, Object> body,OnLoadCookie onLoadCookie);


    /**
     * 获取二维码二进制文件
     * @param ticket
     * @param random
     * @return
     */
    @Get(url = "cgi-bin/mastersafeqrcode?action=getqrcode&qrcheck_ticket=${ticket}&random=${random}&size=120&token=${token}&lang=zh_CN",
        headers = {
            "referer: https://mp.weixin.qq.com/acct/contractorpage?action=showreg&step=3&lang=zh_CN"
        })
    ForestResponse mastersafeqrcodeGetqrcode(@Var("ticket")String ticket,@Var("random")double random,@Var("token")String token,OnLoadCookie onLoadCookie);





    /**
     * 登录他信接口获取token
     * @return
     */
    @Get(url = "http://api.my531.com/Login/?username=${account}&password=${password}&type=json")
    String getTXresData(@Var("account")String account,@Var("password")String password);


    /**
     * 获取公众号他信手机号
     * @return
     */
    @Get(url = "http://api.my531.com/GetPhone/?token=${token}&id=13682&type=json&area=${area}")
    String getTXPhone(@Var("token")String token,@Var("area") String area);


    /**
     * 获取指定手机的验证码
     * @param token
     * @param phone
     * @return
     */
    @Get(url = "http://api.my531.com/GetMsg/?token=${token}&id=13682&phone=${phone}&type=json")
    String getVerificationCode(@Var("token")String token,@Var("phone")String phone);


    /**
     * 获取账号粉丝迁移扫码接口 getticket
     * @return
     */
    @Post(url = "cgi-bin/safeqrcode",headers = {
        "content-type: application/x-www-form-urlencoded; charset=UTF-8",
        "referer: https://mp.weixin.qq.com/acct/biztransfer?action=index&step=agree_proto&token=${token}&lang=zh_CN"
    })
    String getticket(@Body Map<String, Object> body,@Var("token")String token,OnLoadCookie onLoadCookie);


    /**
     * 获取账号粉丝迁移账号二维码
     * @return
     */
    @Get(value = "cgi-bin/safeqrcode?action=getqrcode&qrcheck_ticket=${ticket}&size=165&token=${token}",headers = {
        "referer: https://mp.weixin.qq.com/acct/biztransfer?action=index&step=agree_proto&token=${token}&lang=zh_CN"
    })
    ForestResponse safeqrcode(@Var("ticket")String ticket,@Var("token")String token,OnLoadCookie onLoadCookie);


    /**
     * 粉丝迁移提交协议
     * @param params
     * @param token
     * @param onLoadCookie
     * @return
     */
    @Post(url = "acct/biztransfer?action=submit",headers = {
        "referer: https://mp.weixin.qq.com/acct/biztransfer?action=index&step=agree_proto&token=116840091&lang=zh_CN",
        "content-type: application/x-www-form-urlencoded; charset=UTF-8"
    })
    String biztransfer(@Body Map<String,Object> params,@Var("token")String token,OnLoadCookie onLoadCookie);


    /**
     * 登录投票获取参数
     * @param iid
     * @param ip
     * @param port
     * @param onSaveCookie
     * @return
     */
    @Backend("httpclient")
    @Get(url = "http://xs98e42711.zanyizan.top/getvoteitem/4BLL69CC?iid=${iid}")
    @HTTPProxy(host = "${ip}", port = "${port}")
    String zanyizan(@Var("iid")String iid,@Var("ip")String ip,@Var("port")String port, OnSaveCookie onSaveCookie);


    /**
     *
     * @param params
     * @param onLoadCookie
     * @return
     */

    @Get(url = "http://xs98e42711.zanyizan.top/sendvote/4BLL69CC")
    @HTTPProxy(host = "${ip}", port = "${port}")
    @Backend("httpclient")
    String sendvote(@Body Map<String,Object> params,@Var("ip")String ip,@Var("port")String port, OnLoadCookie onLoadCookie);


    /**
     * 获取视频号绑定设置的扫码参数
     * @param params
     * @param onLoadCookie
     * @return
     */
    @Post(url = "cgi-bin/safeqrcode?action=getticket")
    String getLiveBlocked(@Body Map<String,Object> params,OnLoadCookie onLoadCookie);

    /**
     * 获取视频号绑定设置的二维码
     * @param token
     * @param ticket
     * @param onLoadCookie
     * @return
     */
    @Get(url = "cgi-bin/safeqrcode?action=getqrcode&token=${token}&qrcheck_ticket=${ticket}&size=206")
    ForestResponse getBindSphQRcode(@Var("token")String token,@Var("ticket")String ticket,OnLoadCookie onLoadCookie);

    /**
     * 修改绑定设置
     * @param params
     * @param token
     * @param onLoadCookie
     * @return
     */
    @Post(url = "cgi-bin/settingpage?action=update_bind_finder_setting")
    String updateBindFinderSetting(@Body Map<String,Object> params,@Var("token")String token,OnLoadCookie onLoadCookie);



}
